<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class It_menu_access extends MY_Controller {
	
	function __construct()
	{
		parent::__construct(); 
		
		$this->load->model('it_menu_access_model', 'MenuAccess');
		$this->load->model('combo_model', 'Combo');
		$this->secure_session();
	}
	
	function index(){
		$data['title'] = "Menu Access";
		
		$data['arr_role']	= $this->Combo->SWRole(APP);
		
		viewByTemplate('it_menu_access/index', $data, 'grid');
	}
	
	function getdata()
	{
		echo $this->MenuAccess->GetJSON();
	}
	
	function ajax_post()
	{
		try
		{
			$arr_data	= $this->data;
			for($i=0,$max_i=count($arr_data); $i<$max_i; $i++){
				if(array_key_exists($i,$arr_data)){
					$row	= $arr_data[$i];
					$this->db->delete(	'it_menu_access', 
										array(	'role_id'	=> $row['role_id'], 
												'menu_id'	=> $row['menu_id']));
					if($row['visible'] == '1'){
						$this->db->insert(	'it_menu_access', 
											array(	'role_id'	=> $row['role_id'], 
													'menu_id'	=> $row['menu_id'],
													'cr'		=> $row['c'],
													//'r'		=> $row['r'],
													'up'		=> $row['u'],
													'dl'		=> $row['d'],
													'pr'	=> $row['pr'],
													'dw'	=> $row['dw']));
					}
				}
			}
				
			$ls_response = "Data Tersimpan";
			//App.audit_trail("CS001", "create/" + (data.user_id ?? ""));

		} catch(Exception $e) {
			$is_error = 1; $ls_response = $e->getMessage();
		}
	}
}
?>